package com.zl.learning.annotation;

import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by zhaolei on 2017/7/2.
 */
public class TestAnnotation {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        User u = new User();
        System.out.println(u.getName());
        Class<User> c = User.class;
        Method method = c.getMethod("setName", String.class);
        if (method.isAnnotationPresent(Com.class)) {
            Com com = method.getAnnotation(Com.class);
            method.invoke(u, com.value());
            String val = u.getName();
            System.out.println(val);
        }
    }

    @Test
    @Com("lisi")
    public void test1() {
        System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName());
    }

}

